package com.niit.common

import com.niit.utils.SparkUtil
import org.apache.spark.streaming.Seconds
import org.apache.spark.{SparkConf, SparkContext}

trait TApp {

  def start(master:String ="local[*]",appName:String="appliaction")(op : => Unit) : Unit={
    //一次性创建 spakr Context Spakr Session Spark Streaming
    val sparkConf: SparkConf = new SparkConf().setMaster(master).setAppName(appName)
    val sc: SparkContext = SparkUtil.createSpark(sparkConf,Seconds(5))
    val spark = SparkUtil.takeSpark()
    val ssc = SparkUtil.takeSSC()
    sc.setLogLevel("ERROR")


    try{
      op //是具体的分析过程，可以理解 将分析的代码变成op的变量去表示
    }catch{
      case ex => ex.printStackTrace()
    }

    //关闭
    spark.close()
    ssc.stop(true,true)
    sc.stop()
    SparkUtil.clear()

  }

}
